package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/10.
 */
@HttpInlet(Conn.INLET_GET_HOME_LIST)
public class GetHomeList extends JTAsyGet<GetHomeList.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String obdid = JTApplication.jtPreferences.readOdbID();

    public String date;

    public String lon;

    public String lat;

    public GetHomeList(AsyCallBack<Info> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONObject travel = body.optJSONObject("travel");

        info.totaltime = travel.optString("totaltime");

        info.totalmileage = travel.optString("totalmileage");

        info.averagespeed = travel.optString("averagespeed");

        info.score = travel.optString("score");

        info.today_fuel = travel.optString("fuel");

        info.surplusGprs = travel.optString("surplusGprs");

        JSONArray homeList = body.optJSONArray("poList");

        if(homeList.length()>0){

            for(int i = 0;i<homeList.length();i++) {

                JSONObject home_item = homeList.optJSONObject(i);

                HomeList mList = new HomeList();

                mList.ID = home_item.optString("orderId");

                mList.TITLE = home_item.optString("title");

                mList.MESSAGE = home_item.optString("message");

                mList.TIME = home_item.optString("createTime");

                mList.KEY = home_item.optString("MessageType");

                mList.LON = home_item.optString("lon");

                mList.LAT = home_item.optString("lat");

                mList.MESSAGEVALUE = home_item.optString("MessageValue");

                mList.ADDRESS = home_item.optString("address");

                mList.JPUSHMESSAGE = home_item.optString("jPushMessage");

                mList.MESSAGELEVEL = home_item.optString("message_level");

                info.homeLists.add(mList);

            }

        }

            return info;


    }

    public static class Info implements Serializable {

        public String msg;

        public String totaltime,totalmileage,averagespeed,score;

        public String today_fuel,surplusGprs,today_mileage;

        public List<HomeList> homeLists = new ArrayList<>();

    }

    public static class HomeList implements Serializable {

        public String ID, TITLE, MESSAGE, TIME, KEY,LON,LAT,MESSAGEVALUE,ADDRESS,JPUSHMESSAGE,MESSAGELEVEL;


    }


}
